<?php

class ServerResponse
{
	
	//------------------------------------------------------------------------------
	public function __construct()
	{
		$this->sMsg = "<?xml version='1.0' encoding='utf-8'?>\n<server-response>\n";
	}
		
	//------------------------------------------------------------------------------
	public function getResponse()
	{
		return $this->sMsg."</server-response>\n";
	}

	//------------------------------------------------------------------------------
	public function data( $data )
	{
		// remove < ?xml ... ? > that could be generated by xslt for example
		$iStart = strpos( $data, '<?' );
		if ( $iStart != NULL )
		{
			$iEnd	= strpos( $data, '?>', $iStart );
			$iLength = $iEnd - $iStart + 2; 	
			$data = substr_replace( $data, '', $iStart, $iLength );
		}
		
		$this->sMsg .= '<data><![CDATA['.$data.']]></data>'."\n";
	}
		
	//------------------------------------------------------------------------------
	public function requestExecuted()
	{
		$this->sMsg .= "<executed/>\n";
	}
	
	//------------------------------------------------------------------------------
	public function error( $error )
	{
		$this->sMsg .= '<error> #server# <![CDATA['.$error."]]></error>\n";
	}
	
	//------------------------------------------------------------------------------
	public function exception( $oException )
	{
		$this->sMsg .= '<exception> #server# file : '.$oException->getFile().', line : '.$oException->getLine().', '.$oException->getMessage()."</exception>\n";
	}
	
	//------------------------------------------------------------------------------
	public function warning( $warning )
	{
		$this->sMsg .= '<warning> #server# <![CDATA['.$warning."]]></warning>\n";
	}
	
	//------------------------------------------------------------------------------
	public function info( $info )
	{
		$this->sMsg .= '<info> #server# <![CDATA['.$info."]]></info>\n";
	}
	
	//------------------------------------------------------------------------------
	public function debug( $debug )
	{
		$this->sMsg .= '<debug> #server# <![CDATA['.$debug."]]></debug>\n";
	}

	
	private $sMsg;
};

?>